Completed
Push — master ( 158ed8...34f194 )
by Alejandro
04:53 queued 02:19
created

selectedServer.test.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 48
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 27
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 48
rs 9.232
1
import reducer, {
2
  selectServer,
3
  resetSelectedServer,
4
  RESET_SELECTED_SERVER,
5
  SELECT_SERVER,
6
} from '../../../src/servers/reducers/selectedServer';
7
import { RESET_SHORT_URL_PARAMS } from '../../../src/short-urls/reducers/shortUrlsListParams';
8
9
describe('selectedServerReducer', () => {
10
  describe('reducer', () => {
11
    it('returns default when action is RESET_SELECTED_SERVER', () =>
12
      expect(reducer(null, { type: RESET_SELECTED_SERVER })).toEqual(null));
13
14
    it('returns selected server when action is SELECT_SERVER', () => {
15
      const selectedServer = { id: 'abc123' };
16
17
      expect(reducer(null, { type: SELECT_SERVER, selectedServer })).toEqual(selectedServer);
18
    });
19
  });
20
21
  describe('resetSelectedServer', () => {
22
    it('returns proper action', () => {
23
      expect(resetSelectedServer()).toEqual({ type: RESET_SELECTED_SERVER });
24
    });
25
  });
26
27
  describe('selectServer', () => {
28
    const serverId = 'abc123';
29
    const selectedServer = {
30
      id: serverId,
31
    };
32
    const ServersServiceMock = {
33
      findServerById: jest.fn(() => selectedServer),
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
34
    };
35
36
    afterEach(() => {
37
      ServersServiceMock.findServerById.mockClear();
38
    });
39
40
    it('dispatches proper actions', () => {
41
      const dispatch = jest.fn();
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
42
43
      selectServer(ServersServiceMock)(serverId)(dispatch);
44
45
      expect(dispatch).toHaveBeenCalledTimes(2);
46
      expect(dispatch).toHaveBeenNthCalledWith(1, { type: RESET_SHORT_URL_PARAMS });
47
      expect(dispatch).toHaveBeenNthCalledWith(2, { type: SELECT_SERVER, selectedServer });
48
    });
49
50
    it('invokes dependencies', () => {
51
      selectServer(ServersServiceMock)(serverId)(() => {});
52
53
      expect(ServersServiceMock.findServerById).toHaveBeenCalledTimes(1);
54
    });
55
  });
56
});
57